﻿ 
 //初始化地图,执行的起始点
 function initialize() {
    findDimensions();
    window.onresize=findDimensions;
    initialize2();
//      if (GBrowserIsCompatible()) 
//      {
//        var map = new GMap2(document.getElementById("map_canvas"));
//        map.setCenter(new GLatLng(39.917, 116.397), 14);
//      }
    }
//调整地图区域的长与宽,与浏览器匹配.
var winWidth = 0;
var winHeight = 0;    
function findDimensions() //函数：获取尺寸
{

    //获取窗口宽度
    if (window.innerWidth)
    winWidth = window.innerWidth;
    else if ((document.body) && (document.body.clientWidth))
    winWidth = document.body.clientWidth;
    //获取窗口高度
    if (window.innerHeight)
    winHeight = window.innerHeight;
    else if ((document.body) && (document.body.clientHeight))
    winHeight = document.body.clientHeight;
    //通过深入Document内部对body进行检测，获取窗口大小
    if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth)
    {
    winHeight = document.documentElement.clientHeight;
    winWidth = document.documentElement.clientWidth;
    }

    //alert(document.getElementById("map_canvas").style.height);
    //alert(winHeight);
    document.getElementById("map_canvas").style.height = (winHeight - 99) + 'px';
    //document.getElementById("map_canvas").style.width = (winWidth-195)+"px";
    //document.form1.availWidth.value= winWidth;
    //alert(document.getElementById("map_canvas").style.height);
}


//图片标志
var map = null;
var geocoder = null;
    function initialize2() {
        if (GBrowserIsCompatible()) {
            var mapOptions = {
                googleBarOptions: {
                    style: "new"
                    
                }
            }

// new version GoogleBar
            map = new GMap2(document.getElementById("map_canvas"), mapOptions);

          //map = new GMap2(document.getElementById("map_canvas"));
         map.addControl(new GLargeMapControl());
        map.enableGoogleBar();
        map.enableScrollWheelZoom() ;
        map.enableContinuousZoom();
        G_NORMAL_MAP.getMinimumResolution = function() {
            return 10
        };
        G_NORMAL_MAP.getMaximumResolution = function() {
            return 19
        };
        geocoder = new GClientGeocoder();
        var currentprovince = getCookie("f980", "area");
        if (currentprovince == ""||currentprovince ==null)
            currentprovince = "北京";
        if (currentprovince != "") {
            try {
                currentprovince = decodeURI(currentprovince);
            }
            catch (e) {
                currentprovince = "北京";
            }
            currentprovince = (currentprovince == "吉林") ? "吉林省" : currentprovince;
        }
//        showAddress(currentprovince);
//        
//        //map.addControl(new GSmallMapControl());
// 
//        // 为所有标记创建指定阴影、图标尺寸灯的基础图标
//        var baseIcon = new GIcon();
//        baseIcon.shadow = "http://www.google.cn/mapfiles/shadow50.png";
//        baseIcon.iconSize = new GSize(20, 34);
//        baseIcon.shadowSize = new GSize(37, 34);
//        baseIcon.iconAnchor = new GPoint(9, 34);
//        baseIcon.infoWindowAnchor = new GPoint(9, 2);
//        baseIcon.infoShadowAnchor = new GPoint(18, 25);
// 
//        // 创建信息窗口显示对应给定索引的字母的标记
//        function createMarker(point, index) {
//          // Create a lettered icon for this point using our icon class
//          var letter = String.fromCharCode("A".charCodeAt(0) + index);
//          var letteredIcon = new GIcon(baseIcon);
//          letteredIcon.image = "../img/rain.png";
// 
//          // 设置 GMarkerOptions 对象
//          markerOptions = { icon:letteredIcon };
//          var marker = new GMarker(point, markerOptions);
// 
//          GEvent.addListener(marker, "click", function() {
//            marker.openInfoWindowHtml("标记  <b>" + letter + "</b>");
//          });
//          return marker;
//        }
        
        
      }
    }
    function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert("不能解析: " + address);
            } else {
              map.setCenter(point, 10);
            }
          }
        );
      }
    }